package goover.unit06;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class RunnableDemo02 {
    public static void main(String[] args){
        Thread04 t1 = new Thread04();
        FutureTask<Object> f1 = new FutureTask<>(t1);
        Thread t = new Thread(f1,"t1");
        t.start();
        try {
            System.out.println(f1.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println(f1.cancel(false));
        System.out.println(f1.isCancelled());
        System.out.println(f1.isDone());
    }
}
class Thread04 implements Callable{
    @Override
    public Object call() throws Exception {
        int i = 0;
        while (i++ <10000){
            System.out.println(Thread.currentThread().getName());
        }
        return i;
    }
}